<template>
	<view class="mainpadding ffffff">
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">优惠券名称</view>
			<input class="textright" type="text" placeholder="请输入优惠券名称" v-model="name">
		</view>
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">满减金额</view>
			<input class="textright" type="number" placeholder="请输入满减金额" v-model="mj_price">
		</view>
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">优惠金额</view>
			<input class="textright" type="number" placeholder="请输入优惠金额" v-model="price">
		</view>
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">有效天数</view>
			<input class="textright" type="number" placeholder="请输入有效天数" v-model="days">
		</view>
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">状态</view>
			<view class="flexright">
				<u-radio-group v-model="status" placement="row" circle>
					<u-radio activeColor="#1ba95b" :customStyle="{marginRight: '30rpx'}" label="启用"
						name="normal"></u-radio>
					<u-radio activeColor="#1ba95b" label="隐藏" name="hidden"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="xiahuaxian flexbetween margin_top">
			<view class="ershiba nofonweight xiaohei">是否注册赠送</view>
			<view class="flexright">
				<u-radio-group v-model="is_reg" placement="row" circle>
					<u-radio activeColor="#1ba95b" :customStyle="{marginRight: '30rpx'}" label="否" name="0"></u-radio>
					<u-radio activeColor="#1ba95b" label="是" name="1"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				// price: "99",
				// days: "365",
				// mj_price: "100",
				// status: "normal",
				// name: "福利来了",
				// is_reg: "0",
				price: "",
				days: "",
				mj_price: "",
				status: "normal",
				name: "",
				is_reg: "0",
				user_zbfapply_listid:""
			}
		},
		onLoad(options) {
			this.user_zbfapply_listid=options.user_zbfapply_listid
			if (options.id) {
				uni.setNavigationBarTitle({
					title: "编辑优惠券"
				})
				this.listid = options.id
				this.getDetail()
			}
		},
		methods: {
			getDetail() {
				httpRequest.request('/api/user/fbCouponDetail', 'GET', {
					id: this.listid,
					user_zbfapply_id:this.user_zbfapply_listid
				}).then(res => {
					let data = res.data
					this.name = data.name
					this.days = data.days
					this.status = data.status
					this.is_reg = data.is_reg.toString()
					this.mj_price = data.mj_price
					this.price = data.price
				})
			},
			submit(){
				if(this.name==""){
					httpRequest.toast("请输入优惠券名称")
					return false
				}
				if(this.mj_price==""){
					httpRequest.toast("请输入满减金额")
					return false
				}
				if(this.price==""){
					httpRequest.toast("请输入优惠金额")
					return false
				}
				if(this.days==""){
					httpRequest.toast("请输入有效天数")
					return false
				}
				let url = "/api/user/addCoupon"
				let data = {
					name:this.name,
					mj_price:this.mj_price,
					price:this.price,
					days:this.days,
					status:this.status,
					is_reg:this.is_reg,
					user_zbfapply_id:this.user_zbfapply_listid
				}
				if(this.listid){
					url = "/api/user/editCoupon"
					this.$set(data,"id",this.listid)
				}
				httpRequest.request(url, 'POST', data).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
		}
	}
</script>

<style>

</style>